// mircoApp/coupon_scan_share/coupon_scan_share_Get/coupon_scan_share_Get.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgPath: app.globalData.imgPath,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if (options.scene) {
      let scene = decodeURIComponent(options.scene);
      if (scene) {
        var info_arr = [];
        info_arr = scene.split(",");
        for (let i = 0; i < info_arr.length; i++) {
          let chil_arr = [];
          chil_arr = info_arr[i].split("=");
          if (chil_arr[0] == "mark") {
            this.data.mark = chil_arr[1];
          }
        }
      }
    }
    this.getData();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  async getData() {
    app._getNetWork({
      url: app.getNetAddresss("plugin.coupon-scan-share.frontend.controllers.receive.receive-page"),
      data: {
        mark: this.data.mark
      },
      success: (resdata) => {
        let res = resdata.data;
        if (res.result == 1) {
          this.setData({
            info: res.data
          })
        } else {
          wx.showModal({
            content: res.msg,
            showCancel: false,
            complete: (res) => {
              if (res.confirm) {
                wx.redirectTo({
                  url: '/packageG/index/index',
                })
              }
            }
          })
        }
      }
    });
  },
  tapConfirm() {
    app._getNetWork({
      url: app.getNetAddresss("plugin.coupon-scan-share.frontend.controllers.receive.receive"),
      data: {
        mark: this.data.mark
      },
      success: (resdata) => {
        let res = resdata.data;
        if (res.result == 1) {
          wx.showModal({
            content: res.msg,
            showCancel: false,
            complete: (res) => {
              if (res.confirm) {
                wx.redirectTo({
                  url: '/packageA/member/coupon_v2/coupon_v2',
                })
              }
            }
          })
        } else {
          wx.showModal({
            content: res.msg,
            showCancel: false,
            complete: (res) => {
              if (res.confirm) {
                wx.redirectTo({
                  url: '/packageG/index/index',
                })
              }
            }
          })
        }
      }
    });
  }
})